#include "log.h"
#include <string.h>

logger::logger()
{
	m_writers.clear();
}

logger::~logger()
{
	std::list<log_writer*>::iterator it=m_writers.begin();
	while(it!=m_writers.end())
	{
		delete (*it);
		it++;
	}
}

void logger::bind_writer(log_writer* _writer)
{
	m_writers.push_front(_writer);
}

void logger::write(const char* _string,...)
{
	va_list args;
	va_start(args, _string);
	vsprintf_s(m_buffer,_string,args);
	va_end(args);
	std::list<log_writer*>::iterator it=m_writers.begin();
	while(it!=m_writers.end())
	{
		(*it)->write(m_buffer);
		it++;
	}
}

log_file::log_file(const char* _fname)
{
	m_file.open(_fname,true);
}

log_file::~log_file()
{
	m_file.close();
}

void log_file::write(const char* _string)
{
	m_file.write((void*)_string,(u32)(strlen(_string)));
}